import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useSelectedProgrammeStore = defineStore(
  'selectedProgramme',
  () => {
    const selectedProgrammeList = ref([])

    const addSelectedProgramme = (programme) => {
      selectedProgrammeList.value.push(programme)
    }

    const removeSelectedProgramme = (programme) => {
      selectedProgrammeList.value = selectedProgrammeList.value.filter(
        (item) => item.id !== programme.id,
      )
    }

    const setSelectedProgrammeList = (programmeList) => {
      selectedProgrammeList.value = [...programmeList]
    }

    const clearSelectedProgrammeList = () => {
      selectedProgrammeList.value = []
    }

    return {
      selectedProgrammeList,
      addSelectedProgramme,
      removeSelectedProgramme,
      setSelectedProgrammeList,
      clearSelectedProgrammeList,
    }
  },
)
